package com.joy.openggl.graphics;

import com.joy.openggl.graphics.proto.Rectangle;

public final class Vertices {

	private Vertices() {
	}

	public static float[] createVertices() {
		return new float[8];
	}
	
	public  static float[] getLeftTop(Rectangle rect) {
		return getLeftTop(rect.w, rect.h);
	}
	public  static float[] getLeftTop(int width, int height) {
		return buildLeftTop(createVertices(), width, height);
	}
	public  static float[] buildLeftTop(float[] vertices, Rectangle rect) {
		return buildLeftTop(vertices, rect.w, rect.h);
	}
	public  static float[] buildLeftTop(float[] vertices, int width, int height) {
		vertices[0] = 0;
		vertices[1] = 0;
		
		vertices[2] = width;
		vertices[3] = 0;
		
		vertices[4] = 0;
		vertices[5] = height;
		
		vertices[6] = width;
		vertices[7] = height;
		return vertices;
	}
	
	public  static float[] getRightTop(Rectangle rect) {
		return getRightTop(rect.w, rect.h);
	}
	public  static float[] getRightTop(int width, int height) {
		return buildRightTop(createVertices(), width, height);
	}
	public  static float[] buildRightTop(float[] vertices, Rectangle rect) {
		return buildRightTop(vertices, rect.w, rect.h);
	}
	public  static float[] buildRightTop(float[] vertices, int width, int height) {
		vertices[0] = -width;
		vertices[1] = 0;
		
		vertices[2] = 0;
		vertices[3] = 0;
		
		vertices[4] = -width;
		vertices[5] = height;
		
		vertices[6] = 0;
		vertices[7] = height;
		return vertices;
	}

	public  static float[] getCenter(Rectangle rect) {
		return getCenter(rect.w, rect.h);
	}
	public  static float[] getCenter(int width, int height) {
		return buildCenter(createVertices(), width, height);
	}
	public  static float[] buildCenter(float[] vertices, Rectangle rect) {
		return buildCenter(vertices, rect.w, rect.h);
	}
	public  static float[] buildCenter(float[] vertices, int width, int height) {
		int w2 = width>>1;
		int h2 =  height>>1;
		// 左上
		vertices[0] = -w2;
		vertices[1] = -h2;
		// 右上
		vertices[2] = w2;
		vertices[3] = -h2;
		// 左下
		vertices[4] = -w2;
		vertices[5] = h2;
		// 右下
		vertices[6] = w2;
		vertices[7] = h2;
		return vertices;
	}
	
	public  static float[] getLeftBottom(Rectangle rect) {
		return getLeftBottom(rect.w, rect.h);
	}
	public  static float[] getLeftBottom(int width, int height) {
		return buildLeftBottom(createVertices(), width, height);
	}
	public  static float[] buildLeftBottom(float[] vertices,Rectangle rect) {
		return buildLeftBottom(vertices, rect.w, rect.h);
	}
	public  static float[] buildLeftBottom(float[] vertices, int width, int height) {
		vertices[0] = 0;
		vertices[1] = -height;
		
		vertices[2] = width;
		vertices[3] = -height;
		
		vertices[4] = 0;
		vertices[5] = 0;
		
		vertices[6] = width;
		vertices[7] = 0;
		return vertices;
	}
	
	public  static float[] getRightBottom(Rectangle rect) {
		return getRightBottom(rect.w, rect.h);
	}
	public  static float[] getRightBottom(int width, int height) {
		return buildRightBottom(createVertices(), width, height);
	}
	public  static float[] buildRightBottom(float[] vertices, Rectangle rect) {
		return buildRightBottom(vertices, rect.w, rect.h);
	}
	public  static float[] buildRightBottom(float[] vertices, int width, int height) {
		vertices[0] = -width;
		vertices[1] = -height;
		
		vertices[2] = 0;
		vertices[3] = -height;
		
		vertices[4] = -width;
		vertices[5] = 0;
		
		vertices[6] = 0;
		vertices[7] = 0;
		return vertices;
	}

}
